<html>
<head><script>
var win;
/*var lastDate = localStorage.lastDate || -1;
var ls = localStorage.autoRenew;
var autoRenew = (typeof(ls)=="string")? JSON.parse(ls) : false;
var timer;
if(typeof(lastDate)=="string") {
  lastDate = JSON.parse(lastDate);
}
var periodicFunction = function() {
  ls = localStorage.autoRenew;
  autoRenew = (typeof(ls)=="string")? JSON.parse(ls) : false;
  if(autoRenew) {
    var time = new Date();
    time.setMinutes(time.getMinutes()-15);
    var date = time.getDate();
    if(date != lastDate) {
      localStorage.lastDate = lastDate = date;
      chrome.windows.create({url:"http://catalog.cincinnatilibrary.org/uhtbin/cgisirsi/x/0/0/49?tryrenew=true",type:"popup"}
        ,function(w) { win = w; });
    }
  }
};
setInterval(periodicFunction, 10800000); // three hours * 60 minutes * 60 seconds * 1000 ms = 10800000 ms
setTimeout(periodicFunction, 10000);
*/
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
    if (request.closeWindow && win) {
      chrome.windows.remove(win.id);
      win = null;
    } else if(request.show) {
      chrome.pageAction.show(sender.tab.id);
    } else if(request.hide) {
      chrome.pageAction.hide(sender.tab.id);
    } else if(request.getLibrary) {
      sendResponse(localStorage.library);
    }
  });
</script></head>
</html>